package com.seeyon.apps.kk.listener;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;

import com.seeyon.apps.collaboration.event.CollaborationFinishEvent;
import com.seeyon.apps.collaboration.po.ColSummary;
import com.seeyon.apps.kk.manager.LockKehuEduManager;
import com.seeyon.ctp.common.po.template.CtpTemplate;
import com.seeyon.ctp.util.annotation.ListenEvent;
import com.seeyon.kk.utils.ValueUtils;

public class LockKehuEduListener extends BaseListener{
	private LockKehuEduManager lkem;

	public LockKehuEduManager getLkem() {
		return lkem;
	}
	public void setLkem(LockKehuEduManager lkem) {
		this.lkem = lkem;
	}
	
	 @ListenEvent(event=CollaborationFinishEvent.class, async=true)
	  public void oneStart(CollaborationFinishEvent event) throws Exception {
	    Thread.sleep(BaseListener.LISTENER_THREAD_SLEEPTIME);
	
	    String templetSubject = ValueUtils.getConfig().getString("kk.LockKehuEduListener");
	
	    ColSummary summary = this.colManager.getColSummaryById(event.getSummaryId());
	    CtpTemplate template = this.templateManager.getCtpTemplate(summary.getTempleteId());
	    String[] templetSubjects = StringUtils.split(templetSubject, ",");
	
	    if (ArrayUtils.contains(templetSubjects, template.getTempleteNumber())) {
	      Long id = summary.getFormRecordid();
	      this.lkem.addKehuEduForm(id);
	    }
	  }
	
}
